package bagu.test.duoxiancheng;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author: wzp
 * @CreateTime: 2024-09-14  13:29
 * @Description: 实现多线程的第三种方式，通过创建线程池的方式
 * @Version: 1.0
 */
public class MyThread3 implements Runnable {
    public static int count = 100;
    @Override
    public void run() {
        while (count > 0){
            System.out.println(Thread.currentThread().getName() + ": " + count--);
        }
    }

    public static void main(String[] args) {
        // 创建线程池对象
        ExecutorService threadPool = Executors.newFixedThreadPool(2);
        MyThread3 myThread3 = new MyThread3();
        threadPool.execute(myThread3);
        threadPool.execute(myThread3);
        threadPool.shutdown();
    }
}
